<?php

$tpl = new SimpleTemplate(VIEW."aluno/listarAlunos.html");
$dados = new aluno;
$func = new functions;

$pesquisa = $func->post_isset('pesquisar')->get();
$optionSearch = $func->post_isset('option')->get();


if(empty($pesquisa)){
    $query = "SELECT * FROM aluno";
}
else{
    
    if($optionSearch == 'nome'){
        $query = "SELECT * FROM aluno WHERE nome LIKE '%$pesquisa%' ORDER BY matricula";
    }
    else if($optionSearch == 'matricula'){
        $query = "SELECT * FROM aluno WHERE matricula LIKE '%$pesquisa%' ORDER BY matricula";        
    }    
}

$res = $dados->select_multiple($query);
foreach($res as $nome){
    $tpl->COD = $nome['id'];
    $tpl->MAT = $nome['matricula'];
    $tpl->NOME = $nome['nome'];
        $tpl->SITUACAO = $nome['situacao'];
    $tpl->DTMATRICULA = $func->get_value($nome['dtMatricula'])->to_php_date('d/m/Y')->get();
    
    $tpl->block("BLOCK_ALUNO");
}



$tpl->TOTAL = $dados->total_records();






$tpl->show();
?>
